//
//  ImagePickerExampleViewController.m
//  ImagePickerExample
//

#import "ImagePickerExampleViewController.h"

@implementation ImagePickerExampleViewController

- (void)photoLibraryButtonClick:(id)sender {
	[self presentModalViewController:imagePicker animated:YES];
}

- (void)viewDidLoad {
    [super viewDidLoad];
	
	imagePicker = [[UIImagePickerController alloc] init];
	imagePicker.delegate = self;
	imagePicker.allowsEditing = YES;
	
	UIButton *photoLibraryButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
	[photoLibraryButton setFrame:CGRectMake(100,10,120,34)];
	[photoLibraryButton setTitle:@"Photo Library" forState:UIControlStateNormal];
	[photoLibraryButton addTarget:self action:@selector(photoLibraryButtonClick:)
				 forControlEvents:UIControlEventTouchUpInside];

	[self.view addSubview:photoLibraryButton];
}

- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info {
	[picker dismissModalViewControllerAnimated:YES];
}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
	[picker dismissModalViewControllerAnimated:YES];
}

- (void)dealloc {
	
	[imagePicker release];
	imagePicker = nil;
	
    [super dealloc];
}

@end
